package com.ruoyi.merchant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchant.domain.ProductTastes;
import com.ruoyi.merchant.service.IProductTastesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜品口味Controller
 * 
 * @author ruoyi
 * @date 2025-10-22
 */
@RestController
@RequestMapping("/merchant/tastes")
public class ProductTastesController extends BaseController
{
    @Autowired
    private IProductTastesService productTastesService;

    /**
     * 查询菜品口味列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:tastes:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductTastes productTastes)
    {
        startPage();
        List<ProductTastes> list = productTastesService.selectProductTastesList(productTastes);
        return getDataTable(list);
    }

    /**
     * 导出菜品口味列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:tastes:export')")
    @Log(title = "菜品口味", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductTastes productTastes)
    {
        List<ProductTastes> list = productTastesService.selectProductTastesList(productTastes);
        ExcelUtil<ProductTastes> util = new ExcelUtil<ProductTastes>(ProductTastes.class);
        util.exportExcel(response, list, "菜品口味数据");
    }

    /**
     * 获取菜品口味详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:tastes:query')")
    @GetMapping(value = "/{tasteId}")
    public AjaxResult getInfo(@PathVariable("tasteId") String tasteId)
    {
        return success(productTastesService.selectProductTastesByTasteId(tasteId));
    }

    /**
     * 新增菜品口味
     */
    @PreAuthorize("@ss.hasPermi('merchant:tastes:add')")
    @Log(title = "菜品口味", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductTastes productTastes)
    {
        return toAjax(productTastesService.insertProductTastes(productTastes));
    }

    /**
     * 修改菜品口味
     */
    @PreAuthorize("@ss.hasPermi('merchant:tastes:edit')")
    @Log(title = "菜品口味", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductTastes productTastes)
    {
        return toAjax(productTastesService.updateProductTastes(productTastes));
    }

    /**
     * 删除菜品口味
     */
    @PreAuthorize("@ss.hasPermi('merchant:tastes:remove')")
    @Log(title = "菜品口味", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tasteIds}")
    public AjaxResult remove(@PathVariable String[] tasteIds)
    {
        return toAjax(productTastesService.deleteProductTastesByTasteIds(tasteIds));
    }
}
